import { IToolTipItem } from "../../../../com/mui/manager/IToolTipItem";
import { BaseItem } from "../common/BaseItem";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { GTextFormat } from "../../../common/GTextFormat";
import { ItemData } from "../../resource/info/ItemData";
import { WuXingRule } from "../../rules/WuXingRule";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../extend/language/Language";
import { ColorConfig } from "../../resource/ColorConfig";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { WuXingCache } from "../../cache/WuXingCache";
import { ToolTipsManager } from "../../../../com/mui/manager/ToolTipsManager";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
//class WuXingGradeEquipItem
    
    export  class WuXingGradeEquipItem /* flash.display.Sprite */ implements IToolTipItem
    {
        constructor()
        {
            
            this.initUI();
            addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onMouseOverHandler);
            return;
        }

        /* internal  */onMouseOverHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onMouseOutHandler);
            return;
        }

        /* internal  */onMouseOutHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            removeEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onMouseOutHandler);
            return;
        }

        protected initUI(): void
        {
            this._baseItem = new BaseItem();
            this._baseItem.setSize(32, 32);
            this._baseItem.isDragAble = false;
            this._baseItem.x = 3;
            this._baseItem.y = 3;
            addChild(this._baseItem);
            this._nameBg = ObjCreate.createBg(-6, this._baseItem.y + this._baseItem.height + 4, this.width - 4, 14, this, ImagesConst.FightingStrgBg);
            var loc1=new GTextFormat("", 12, 16776960);
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._nameTxt = ObjCreate.createTextField("", 0, this._nameBg.y, this.width, 20, this, loc1);
            this._nameTxt.autoSize = flash.text.TextFormatAlign.CENTER;
            this._nameTxt.textColor = 16776960;
            this._nameTxt.x = 17;
            this._nameTxt.y = this._nameBg.y - 2;
            this.mouseChildren = false;
            return;
        }

        public updateData(arg1: ItemData, arg2: Boolean=true): void
        {
            this._itemData = arg1;
            if (this._itemData) 
            {
                this._baseItem.itemData = this._itemData;
                if (arg2) 
                {
                    if (WuXingRule.wxGradeAble(arg1)) 
                    {
                        this._nameTxt.htmlText = HTMLUtil.addColor(Language.getStringByParam(26304, this._itemData.wxColor, this._itemData.wxLevel), ColorConfig.instance.getItemColorString(this._itemData.wxColor));
                        filters = null;
                        this.toolTipData = this._itemData.getToolTipData(ItemData.ToolTipType_Forge);
                    }
                    else 
                    {
                        this._nameTxt.htmlText = HTMLUtil.addColor(Language.getStringByParam(26304, 0, 0), ColorConfig.instance.getItemColorString(0));
                        filters = [FilterConst.colorFilter];
                        this.toolTipData = HTMLUtil.addColor(Language.getString(26305), "#ffffff");
                    }
                }
                else if (arg1.itemInfo.item.level >= WuXingCache.SHENGLINGOPENLV) 
                {
                    this._nameTxt.htmlText = HTMLUtil.addColor(Language.getStringByParam(73021, this._itemData.wxShenglingLV), ColorConfig.instance.getItemColorString(1));
                    filters = null;
                    this.toolTipData = this._itemData.getToolTipData(ItemData.ToolTipType_Forge);
                }
                else 
                {
                    this._nameTxt.htmlText = HTMLUtil.addColor(Language.getStringByParam(73021, this._itemData.wxShenglingLV), ColorConfig.instance.getItemColorString(0));
                    filters = [FilterConst.colorFilter];
                    this.toolTipData = HTMLUtil.addColor(Language.getString(73020), "#ffffff");
                }
            }
            else 
            {
                this._nameTxt.text = "";
                this.toolTipData = null;
                filters = null;
            }
            return;
        }

        public dispose(): void
        {
            this.mouseDown(false);
            this._itemData = null;
            this._nameTxt.text = "";
            this.toolTipData = null;
            filters = null;
            return;
        }

        public mouseDown(arg1: Boolean): void
        {
            if (arg1) 
            {
                this.filters = [FilterConst.guideTipsFilter];
            }
            else 
            {
                this.filters = null;
            }
            return;
        }

        public get item(): ItemData
        {
            return this._itemData;
        }

        public /* override */ get width(): number
        {
            return 56;
        }

        public /* override */ get height(): number
        {
            return 58;
        }

        public get toolTipData()
        {
            return this._tooltipData;
        }

        public set toolTipData(arg1)
        {
            if (arg1 == null || arg1 == "") 
            {
                ToolTipsManager.unregister(this);
            }
            else 
            {
                ToolTipsManager.register(this);
            }
            this._tooltipData = arg1;
            return;
        }

        protected /* var */_itemData: ItemData;

        protected /* var */_nameBg: ScaleBitmap;

        protected /* var */_nameTxt: Object /* flash.text.TextField */;

        protected /* var */_baseItem: BaseItem;

        /* internal */ /* var */_tooltipData;
    }
